package cn.michael.dev.data.structure.stack;

import cn.michael.dev.entity.ListNode;

/**
 * Created by hufenggang on 2021/8/24.
 *
 * 基于链表实现栈
 */
public class LinkedListStack {
    private ListNode top = null;

    /**
     * 入栈
     *
     * @param value
     */
    public void push(int value) {
        ListNode newNode = new ListNode(value, null);
        // 判断是否栈空
        if (top == null) {
            top = newNode;
        } else {
            newNode.next = top;
            top = newNode;
        }
    }
}
